package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyFertilizerInfo;
import com.ruoyi.ncpsy.service.INcpsyFertilizerInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 肥料信息Controller
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/ncpsy/fertInfo")
public class NcpsyFertilizerInfoController extends BaseController
{
    @Autowired
    private INcpsyFertilizerInfoService ncpsyFertilizerInfoService;

    /**
     * 查询肥料信息列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsyFertilizerInfo ncpsyFertilizerInfo)
    {
        startPage();
        List<NcpsyFertilizerInfo> list = ncpsyFertilizerInfoService.selectNcpsyFertilizerInfoList(ncpsyFertilizerInfo);
        return getDataTable(list);
    }

    /**
     * 导出肥料信息列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertInfo:export')")
    @Log(title = "肥料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyFertilizerInfo ncpsyFertilizerInfo)
    {
        List<NcpsyFertilizerInfo> list = ncpsyFertilizerInfoService.selectNcpsyFertilizerInfoList(ncpsyFertilizerInfo);
        ExcelUtil<NcpsyFertilizerInfo> util = new ExcelUtil<NcpsyFertilizerInfo>(NcpsyFertilizerInfo.class);
        util.exportExcel(response, list, "肥料信息数据");
    }

    /**
     * 获取肥料信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertInfo:query')")
    @GetMapping(value = "/{fertId}")
    public AjaxResult getInfo(@PathVariable("fertId") Long fertId)
    {
        return success(ncpsyFertilizerInfoService.selectNcpsyFertilizerInfoByFertId(fertId));
    }

    /**
     * 新增肥料信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertInfo:add')")
    @Log(title = "肥料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyFertilizerInfo ncpsyFertilizerInfo)
    {
        return toAjax(ncpsyFertilizerInfoService.insertNcpsyFertilizerInfo(ncpsyFertilizerInfo));
    }

    /**
     * 修改肥料信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertInfo:edit')")
    @Log(title = "肥料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyFertilizerInfo ncpsyFertilizerInfo)
    {
        return toAjax(ncpsyFertilizerInfoService.updateNcpsyFertilizerInfo(ncpsyFertilizerInfo));
    }

    /**
     * 删除肥料信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertInfo:remove')")
    @Log(title = "肥料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertIds}")
    public AjaxResult remove(@PathVariable Long[] fertIds)
    {
        return toAjax(ncpsyFertilizerInfoService.deleteNcpsyFertilizerInfoByFertIds(fertIds));
    }
}
